#ifndef __INIT_H
#define __INIT_H

#include <string.h>

#include "helper.h"
#include "cfd_utils.h"


/* disallow debugging statement */
#undef DEBUG


/* ======================================================================================== */

/**
 * This operation initializes all the local variables reading a configuration
 * file. For every variable a macro like READ_INT() is called passing it the
 * input filename and the variable to be written to. This macro calls
 * an operation read_int() augmenting the parameter set with the name of the
 * variable to be read. The read_int() operation parses the input file, extracts
 * the value of the variable, sets the variable and finally prints some debug
 * information. This is possible as the macro adds the name of the variable to
 * be set. All the helper operations can be found within helper.h and helper.c.
 *
 * @param szFileName	char pointer to the filename
 * @param Re		Reynolds number
 * @param UI		initial velocity in  x-direction - used by init_uvp()
 * @param VI		initial velocity y-direction - used by init_upv()
 * @param PI		initial pressure - used by init_upv()
 * @param GX		gravitation x-direction
 * @param GY		gravitation y-direction
 * @param t_end		end time (not discrete in time steps)
 * @param xlength	domain length x-direction
 * @param ylength	domain lenght y-direction
 * @param dt		time step length: dividing t_end by dt gives the number of
 *			time steps to perform. Actually dt is determined by a
 *			function, so manipulating this value within the
 *			configuration file should not affect the solution process at all
 * @param dx		cell length x-direction
 * @param dy		cell length y-direction
 * @param imax		number of cells in x-direction
 * @param jmax		number of cells in Y-direction
 * @param alpha		uppwind-differencing-factor alpha
 * @param omg		relaxation factor omega
 * @param tau		safety parameter for time step calculation
 * @param itermax	max. number of pressure iterations
 * @param eps		tolerance limit for pressure calculation
 * @param dt_value	time steps for output (after how many time steps one should write into the output file)
 * @param wl		The boundary condition value for the left boundary
 * @param wr		The boundary condition value for the right boundary
 * @param wt		The boundary condition value for the top boundary
 * @param wb		The boundary condition value for the bottom boundary
 * @param problem	The problem name
 * @param N		The number of particles equidistantly distributed over the line specified by (x1,y1) and (x2,y2)
 * @param x1		The x-coordinate of the 1st point in the line used for particles/streaklines tracing
 * @param y1		The y-coordinate of the 1st point in the line used for particles/streaklines tracing
 * @param x2		The x-coordinate of the 2nd point in the line used for particles/streaklines tracing
 * @param y2		The y-coordinate of the 2nd point in the line used for particles/streaklines tracing
 * @param dt_path	The time step used to output path-lines
 * @param dt_streak	The time step used to output streak-lines
 * @param dt_insert	The time step used to insert new particles in the case of streak-lines
 * @param dp		The pressure difference between the left and right boundaries
 * @param driving_velocity		The value of the driving velocity
 * @param ppc		The number of particles per cell in each dimension
 *
 * @return 1
 */
int read_parameters(
	const char *szFileName,
	double *Re,
	double *UI,
	double *VI,
	double *PI,
	double *GX,
	double *GY,
	double *t_end,
	double *xlength,
	double *ylength,
	double *dt,
	double *dx,
	double *dy,
	int  *imax,
	int  *jmax,
	double *alpha,
	double *omg,
	double *tau,
	int  *itermax,
	double *eps,
	double *dt_value,
	int *wl,
	int *wr,
	int *wt,
	int *wb,
	double *dp,
	char *problem,
	int *N,
	double *x1,
	double *y1,
	double *x2,
	double *y2,
	double *dt_path,
	double *dt_streak,
	double *dt_insert,
	double *driving_velocity,
	int *ppc
);

/**
 * The arrays U,V and P are initialized to the constant values UI, VI and PI on
 * the whole domain.
 * @param	UI		Initial value of U
 * @param	VI		Initial value of V
 * @param	PI		Initial value of P
 * @param	imax		imax Number of interior cells in x-direction
 * @param	jmax		Number of interior cells in y-direction
 * @param	U		The velocity in x-direction
 * @param	V		The velocity in y-direction
 * @param	P		The Pressure
 */
void init_uvp(
	double UI,
	double VI,
	double PI,
	int imax,
	int jmax,
	double **U,
	double **V,
	double **P
);

/**
 * Initializes the Flag array with the appropiate values for fluid and obstacle cells
 * @param	problem		The problem name
 * @param	imax		imax Number of interior cells in x-direction
 * @param	jmax		Number of interior cells in y-direction
 * @param	Flag		The fluid-obstacle matrix
 */
void init_flag(
		char *problem,
		int imax,
		int jmax,
		int **Flag
		);

#endif
